home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / diskio.c < prev    next >
C/C++ Source or Header  |  1985-10-30  |  6KB  |  172 lines

  1. /* diskio.c with sun makefile v1.0 *
  2. /****************************************************************
  3. *                                                               *
  4. * Copyright 1985, Commodore Amiga Inc.  All rights reserved.    *
  5. * No part of this program may be reproduced, transmitted,       *
  6. * transcribed, stored in retrieval system, or translated into   *
  7. * any language or computer language, in any form or by any      *
  8. * means, electronic, mechanical, magnetic, optical, chemical,   *
  9. * manual or otherwise, without the prior written permission of  *
  10. * Commodore Amiga Incorporated, 983 University Ave, #D          *
  11. * Los Gatos, CA 95030                                           *
  12. *                                                               *
  13. ****************************************************************/
  14.  
  15. /*** Makefile ***************************/
  16.  
  17.  
  18. all: diskio.ld
  19.  
  20. SUBSYSNAME=     diskio
  21.  
  22. AFILES=         diskio.asm 
  23. CFILES=         diskio.c
  24. OFILES=         diskio.obj
  25. MYLIBS= ${LIBDIR}/debug.lib
  26.  
  27. MAKEFILE=       Makefile
  28. SUBSYSGROUP=    
  29. EXTERNIFILES=
  30. IFILES=         ${EXTERNIFILES}
  31. EXTERNHFILES=   intuall.h
  32. HFILES=         global.h ${EXTERNHFILES}
  33. LFLAGS=         map=$*.lmap xref=$*.xref
  34.  
  35. STARTUP=        $(VERDIR)/$(TERNAL)/lib/startup.obj
  36. CFLAGS= -DDEBUG
  37.  
  38. .INCLUDE=/usr/commodore/amiga/V1/tools/makemeta
  39.  
  40.  
  41.  
  42.  
  43. /*** diskio.c ***************************/
  44.  
  45. #include <exec/types.h>
  46. #include <exec/io.h>
  47. #include <devices/trackdisk.h>
  48.  
  49. #define TD_READ CMD_READ
  50. #define BLOCKSIZE TD_SECTOR
  51.  
  52. SHORT error;
  53. struct Port *diskport;
  54. struct IOStdReq *diskreq;
  55. BYTE diskbuffer[BLOCKSIZE];
  56. BYTE *diskdata;
  57. SHORT testval;
  58.  
  59. extern struct Port *CreatePort();
  60. extern struct IOStdReq *CreateStdIO();
  61.         
  62.                 
  63. ReadCylSec(cyl, sec, hd)
  64. SHORT cyl, sec, hd;
  65. {
  66.         LONG offset;
  67.  
  68.         diskreq->io_Length = BLOCKSIZE;      
  69.         diskreq->io_Data = diskbuffer;  
  70.                 /* show where to put the data when read */
  71.         diskreq->io_Command = TD_READ;
  72.         
  73.         /* convert from cylinder, head, sector to byte-offset value to get
  74.          * right one (as dos and everyone else sees it)...*/
  75.         
  76.         /* driver reads one CYLINDER at a time (head does not move for
  77.          * 22 sequential sector reads, or better-put, head doesnt move for
  78.          * 2 sequential full track reads.)
  79.          */
  80.         
  81.         offset = TD_SECTOR * (sec + NUMSECS * hd + NUMSECS * NUMHEADS * cyl);
  82.         diskreq->io_Offset = offset;
  83.         DoIO(diskreq);
  84.         return;
  85. }
  86.  
  87.  
  88. MotorOn()
  89. {
  90.         /* TURN ON DISK MOTOR ... old motor state is returned in io_Actual */
  91.         diskreq->io_Length = 1; /* this says motor is to be turned on */
  92.         diskreq->io_Command = TD_MOTOR; /* do something with the motor */
  93.         DoIO(diskreq);
  94.         printf("\nOld motor state was: %ld",diskreq->io_Actual);
  95.         printf("\nio_Error value was: %ld",diskreq->io_Error);
  96.         return;
  97. }
  98.  
  99. MotorOff()
  100. {
  101.         printf("\n\nNow turn it off");
  102.         diskreq->io_Length = 0; /* says that motor is to be turned on */
  103.         diskreq->io_Command = TD_MOTOR; /* do something with the motor */
  104.         DoIO(diskreq);
  105.         printf("\nOld motor state was: %ld",diskreq->io_Actual);
  106.         printf("\nio_Error value was: %ld",diskreq->io_Error);
  107.         return;
  108. }
  109.  
  110. SeekFullRange(howmany)
  111. SHORT howmany;
  112. {
  113. SHORT i;
  114. for(i=0; i<howmany; i++)
  115.         {
  116.         diskreq->io_Offset = ((NUMCYLS -1)*NUMSECS*NUMHEADS -1 ) * 512;
  117.         /* seek to cylinder 79, head 1 */
  118.         diskreq->io_Command = TD_SEEK;
  119.         DoIO(diskreq);
  120.         if(diskreq->io_Error != 0) 
  121.                 printf("\nSeek Cycle Number %ld, Error = %ld",
  122.                                         i, diskreq->io_Error);
  123.         diskreq->io_Offset = 0;
  124.                 /* seek to cylinder 0, head 0 */
  125.         diskreq->io_Command = TD_SEEK;
  126.         DoIO(diskreq);
  127.         if(diskreq->io_Error != 0) 
  128.                 printf("\nSeek Cycle Number %ld, Error = %ld",
  129.                                         i, diskreq->io_Error);
  130.         printf("\nCompleted a seek");
  131.         }
  132. return;
  133. }
  134.  
  135.  
  136. main()
  137. {
  138.         LONG i,j;
  139.         SHORT cylinder,head,sector;
  140.         
  141.         diskdata = &diskbuffer[0];      
  142.                 /* point to first location in disk buffer */
  143.         diskport = CreatePort(0,0);
  144.         diskreq = CreateStdIO(diskport);     
  145.                 /* make an io request block for communicating with the disk */
  146.  
  147.         for(j=0; j<2; j++)
  148.         {       /* do both drives 0 and 1 */
  149.         error = OpenDevice(TD_NAME,j,diskreq,0);
  150.                 /* open the device for access, unit 0 is builtin drive */
  151.         printf("\nError value returned by OpenDevice was: %lx", error);
  152.         MotorOn();
  153.         SeekFullRange(10);
  154.         for(cylinder=0; cylinder<80; cylinder++)        /* tracks to test */
  155.            {
  156.            for(head=0; head<2; head++)  /* number of heads to test */
  157.                 for(sector=0; sector<11; sector++)      /* sectors to test */
  158.                 {
  159.                 ReadCylSec(cylinder, sector, head);
  160.                 if(diskreq->io_Error != 0) 
  161.                         printf("\nError At Cyl=%ld, Sc=%ld, Hd=%ld, Error=%ld",
  162.                                 cylinder,sector,head,diskreq->io_Error);
  163.                 }
  164.             printf("\nCompleted reading Cylinder=%ld",cylinder);
  165.             }
  166.         MotorOff();
  167.         CloseDevice(diskreq);
  168.         }       /* end of for-loop testing second drive */
  169.         DeleteStdIO(diskreq);
  170.         DeletePort(diskport);
  171. }               /* end of main */
  172.